package com.homework.note.Service.impl;

import com.homework.note.Model.Enum.TrashType;
import com.homework.note.Model.Note;
import com.homework.note.Model.Notebook;
import com.homework.note.Model.Trash;
import com.homework.note.Repository.NoteRepository;
import com.homework.note.Repository.NotebookRepository;
import com.homework.note.Repository.TrashRepository;
import com.homework.note.Service.TrashService;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.client.gridfs.GridFSBuckets;
import com.mongodb.client.gridfs.GridFSDownloadStream;
import com.mongodb.client.gridfs.model.GridFSFile;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.data.mongodb.gridfs.GridFsResource;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.springframework.data.mongodb.core.query.Criteria.where;

/**
 * @author htyu
 * @date 2019/3/10
 */

@Service
public class TrashServiceImpl implements TrashService {

    @Autowired
    TrashRepository trashRepository;

    @Autowired
    NotebookRepository notebookRepository;

    @Autowired
    MongoDbFactory mongoDbFactory;

    @Autowired
    GridFsOperations fs;

    @Autowired
    GridFSBucket gridFSBucket;



    @Override
    public List<Trash> getList() {
        return trashRepository.findAll();
    }

    @Override
    public String delete(String trashID){
        Trash trash = trashRepository.findById(trashID).orElseThrow(()->new RuntimeException("待删除对象不存在"));
        trashRepository.delete(trash);
        return "永久删除成功";
    }

    @Override
    public Object restore(String trashID) {
        Trash trash = trashRepository.findById(trashID).orElseThrow(() -> new RuntimeException("待恢复对象不存在"));
        return trash;
    }
}
